﻿using System;
using System.Drawing;
using System.Windows.Ink;
using System.Windows.Media;
using MCPlatform.Dxf.Utils;
using netDxf;
using netDxf.Entities;

namespace MCPlatform.Dxf.Entities
{
    /// <summary>
    /// 表示DXF文件中的线段路径实体。
    /// </summary>
    public class LinePathEntity : PathEntityBase
    {
        #region Properties

        

       
        public Line Line { get; }

       

        #endregion


        /// <summary>
        /// 使用给定的DXF线段初始化线段路径实体。
        /// </summary>
        /// <param name="line">要从中创建线段路径实体的DXF线段</param>
        /// <exception cref="ArgumentNullException">如果传入的DXF线段为null</exception>
        public LinePathEntity(Line line)
        {
            Line = line;
            StartPoint = new Vector3(line.StartPoint.X, line.StartPoint.Y, line.StartPoint.Z);
            EndPoint = new Vector3(line.EndPoint.X, line.EndPoint.Y, line.EndPoint.Z);
            Type = line;
            Handle = line.Handle;

            Length = Vector3.Distance((Vector3)StartPoint, (Vector3)EndPoint);


            DrawShape(line);
        }

        public void DrawShape(Line? line,float scaleX = 1,float scaleY = 1, float strokeThickness = 1)
        {
            if (line is null)
            {
                line = this.Line;
            }

            PointF start = new PointF((float)line.StartPoint.X, (float)line.StartPoint.Y);
            PointF end = new PointF((float)line.EndPoint.X, (float)line.EndPoint.Y);

            System.Windows.Shapes.Line drawLine = new System.Windows.Shapes.Line();
            drawLine.Stroke = Utility.ConvertAciColorToBrush(line.Color);
            drawLine.X1 = end.X * scaleX;
            drawLine.X2 = start.X * scaleX;
            drawLine.Y1 = end.Y * scaleY;
            drawLine.Y2 = start.Y * scaleY;
            drawLine.StrokeThickness = Utility.GetNumberFromTextToFloat(line.Lineweight.ToString(), line.Layer.Lineweight.ToString()) ?? strokeThickness;
            drawLine.IsHitTestVisible = false;

            this.Shape = drawLine;

            this.Shape.Tag = line.Handle;
        }


        internal LinePathEntity()
        {
        }
    }
}